<template>
	<view>
		<!-- 顶部导航栏 -->
		<cu-custom bgColor="bg-gradual-green" :isBack="true">
			<block slot="content">我的试听课</block>
		</cu-custom>
		
		<message ref="message"></message>
		
		<!-- 课程列表 -->
		<view v-for="(item, index) in myList" :key="index">
			<view class="cu-card margin padding-sm radius bg-white" @click="handleCourseInfo(item)">
				<view class="flex align-center solid-bottom padding-tb-sm">
					<text class="cuIcon-titles text-green"></text>
					<text class="text-xl text-bold">{{item.name}}</text>
				</view>
				<view class="margin-top text-black text-lg padding-left">
					试听课时间： {{parseTime(item.experienceTime, '{y}年{m}月{d}日 {h}:{i}')}}
				</view>
			</view>
		</view>
		
		
	</view>
</template>

<script>
	import CourseListItem from "@/components/course-list-item/course-list-item.vue"
	import { getStudentExperienceList } from "@/api/experience.js"
	import { parseTime } from "@/utils/parse.js"
	
	export default {
		components:{
			CourseListItem
		},
		data() {
			return {
				myList: []
			}
		},
		created() {
			if(!uni.getStorageSync('token')){
				uni.navigateTo({
					url: "/pages/login/login"
				})
			}
			this.getList()
		},
		methods: {
			parseTime,
			// 获取体验课程列表
			getList() {
				getStudentExperienceList().then(res => {
					this.myList = res.data
				})
			},
			// 跳转课程详情页面
			handleCourseInfo(item) {
				this.$store.commit('course/set_courseId', item.courseId)
				uni.navigateTo({
					url: '/pages/course/course-detail/course-detail'
				})
			}
		}
	}
</script>

<style>

</style>
